import service from '@/api/service'
import type { Page } from '@/type/User'
import type { PageQuery } from '@/type/common/list-types'
import type { RoleDto, RoleVo } from '@/type/system/role-types'

const mapping = 'role'


/** 条件分页查询角色列表 */
export const roleListApi = (pageQuery: PageQuery) =>
  service.post<Page<RoleVo[]>>(`${mapping}/page`, pageQuery)

/** 根据角色id查询角色信息 */
export const roleInfoApi = (roleId: string) =>
  service.get<RoleVo>(`${mapping}/${roleId}`)

/** 保存角色信息 */
export const saveRoleApi = (role: RoleDto) =>
  service.put(`${mapping}`, role)

/** 查询角色下权限列表信息 */
export const rolePermListApi = (roleId: string) =>
  service.get<string[]>(`${mapping}/perm/${roleId}`)

/** 保存角色下权限列表信息 */
export const saveRolePermApi = (roleId: string, permsId: string[]) =>
  service.post(`${mapping}/perm/${roleId}`, permsId)